import { createRouter, createWebHashHistory, type RouteRecordRaw } from 'vue-router'
import {KeepAlive, type App} from 'vue'
export const Layout = ()=>import("@/layout/index.vue")
// 静态路由
export const constantRoutes:RouteRecordRaw[] = [
  {
    path:'/redirect',
    component:Layout,
    meta:{hidden:true},
    children:[
      {
        path:"/redirect/:path(.*)",
        component:()=>import("@/views/redirect/index.vue"),
      }
    ]
  },
  {
    path:"/login",
    component:()=>import("@/views/login.vue"),
    meta:{hidden:true}
  },
  {
    path:"/",
    component:Layout,
    redirect:'/sy',
    children:[
      {
        path:"sy",
        component:()=>import("@/views/shou/sy.vue"),
        meta:{
          icon:"homepage",
          affix:true,
          KeepAlive:true,
          alwaysShow:false,
        }
      },
      {
        path:"401",
        component:()=>import("@/views/error/401.vue"),
        meta:{hidden:true},
      },
      {
        path:"404",
        component:()=>import("@/views/error/404.vue"),
        meta:{hidden:true},
      },
    ]
  }
]

/* createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      redirect:'/login'
    },
    {
      path: '/home',
      name: '首页',
      component: () => import('@/views/home.vue'),
      children:[
        {
          path:'/home',
          redirect:'/sy'
        },
        {
          path:'/sy',
          name:'首页',
          component:()=> import('@/views/shou/sy.vue')
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login.vue')
    },
    {
      path: '/system',
      name: '系统管理',
      component: () => import('@/views/home.vue'),
      children:[
        {
          path:'/system/yhgl',
          name:"用户管理",
          component:()=> import('@/views/children/yhgl.vue'),
        },
        {
          path:'/system/jsgl',
          name:"角色管理",
          component:()=> import('@/views/children/jsgl.vue'),
        },
        {
          path:'/system/cdgl',
          name:"菜单管理",
          component:()=> import('@/views/children/cdgl.vue'),
        },
        {
          path:'/system/bmgl',
          name:"部门管理",
          component:()=> import('@/views/children/bmgl.vue'),
        },
        {
          path:'/system/zdgl',
          name:"字典管理",
          component:()=> import('@/views/children/zdgl.vue'),
        }
      ]
    },
    {
      path:'/api',
      name:'接口文档',
      component:() => import('@/views/home.vue'),
      children:[
        {
          path:'/api/apifox',
          name:'Apifox',
          component:()=> import('@/views/children/apifox.vue'),
        }
      ]
    },
    {
      path:'/doc',
      name:'平台文档',
      component:() => import('@/views/home.vue'),
      children:[
        {
          path:'/doc/ptOne',
          name:'平台文档(内嵌)',
          component:()=> import('@/views/children/ptOne.vue')
        },
        {
          path:'/doc/ptTwo',
          name:'平台文档(外链)',
          component:()=> import('@/views/children/ptTwo.vue')
        }
      ]
    },
    {
      path:'/multi-level',
      name:'多级菜单',
      component:() => import('@/views/home.vue'),
      children:[
        {
          path:'/multi-level/cdyj',
          name:'菜单一级',
          component:()=> import('@/views/children/cdyj.vue')
        }
      ]
    },
    {
      path:'/component',
      name:'组件封装',
      component:() => import('@/views/home.vue'),
      children:[
        {
          path:'/component/zsgc',
          name:'增删改查',
          component:()=> import('@/views/children/zsgc.vue')
        },
        {
          path:'/component/lb',
          name:'列表选择器',
          component:()=> import('@/views/children/lb.vue')
        },
        {
          path:'/component/fwb',
          name:'富文本编辑器',
          component:()=> import('@/views/children/fwb.vue')
        },
        {
          path:'/component/imgs',
          name:'图片上传',
          component:()=> import('@/views/children/imgs.vue')
        },
        {
          path:'/component/icons',
          name:'图标选择器',
          component:()=> import('@/views/children/icons.vue')
        }
      ]
    },
    {
      path:'/route-param',
      name:'路由参数',
      component:() => import('@/views/home.vue'),
      children:[
        {
          path:'/route-param/lyOne',
          name:'参数(type=1)',
          component:()=> import('@/views/children/lyOne.vue')
        },
        {
          path:'/route-param/lyTwo',
          name:'参数(type=2)',
          component:()=> import('@/views/children/lyTwo.vue')
        }
      ]
    },
    {
      path:'/function',
      name:'功能演示',
      component:() => import('@/views/home.vue'),
      children:[
        {
          path:'/function/iconse',
          name:'Icons',
          component:()=> import('@/views/children/iconse.vue')
        },
        {
          path:'/function/web',
          name:'WebSocket',
          component:()=> import('@/views/children/web.vue')
        },
        {
          path:'/function/jqqd',
          name:'敬请期待...',
          component:()=> import('@/views/children/jqqd.vue')
        }
      ]
    },
  ]
}) */

// 创建路由
const router = createRouter({
  history:createWebHashHistory(),
  routes:constantRoutes,
  // 刷新时,滚动条位置还原
  scrollBehavior:()=>({left:0,top:0})
})

// 全局注册router
export function setupRouter(app:App<Element>){
  app.use(router)
}
// 重置路由
export function resetRouter(){
  router.replace({path:'/login'})
}
export default router;
